//
//  STHairService.m
//  YiYueHairdresser
//
//  Created by 路人甲 on 2018/10/31.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STHairService.h"

#define requestIP  BASEURL //@"http://192.168.0.187:8021/"
#define requestIP1105 BASEURL


//查询认证状态

static NSString * const examineStatusUrl = @"stylistAuthApply/getStylistAuthStatusByStylistId";

//美发师服务删除
static NSString * const deleteStylistServerUrl = @"stylistServer/delete";
static NSString * const getServiceInfoUrl = @"stylistServer/getServiceInfo";
static NSString * const lineStatusUrl = @"stylistServer/isOnline";
static NSString * const serviceListUrl = @"stylistServer/list";
static NSString * const saveServiceUrl = @"stylistServer/save";
//订单统计

static NSString * const stylistOrderCountUrl = @"stylistOrderCount/getStylistOrderCount";
static NSString * const stylistSuccessOrderCountUrl = @"stylistOrderCount/getStylistSuccessOrders";



//美发师服务类目
static NSString * const getConditionUrl = @"category/getByCondition";
//按ID获取平台类目
static NSString * const getCategoryUrl = @"category/getCategoryById";

//查询美发师的时间设置列表
static NSString * const getStylistTimeUrl = @"stylistTimeSetting/getStylistTimeSettingByStylistId";
//单个的新增或者更新
static NSString * const updateOneStylistTimeUrl = @"stylistTimeSetting/updateOrSave";
//多个数据的新增或者更新
static NSString * const updateAeeStylistTimeUrl = @"stylistTimeSetting/updateOrSaves";

//获取门店审核状态URL
static NSString * const getNexuStatusUrl = @"joinStore/getNexuStatus";
//获取美发师入住门店
static NSString * const getHairStoreUrl = @"joinStore/myStore";
//美发师申请门店
static NSString * const joinStoreUrl = @"joinStore/nexusStore";
//美发师解约
static NSString * const relieveStoreUrl = @"joinStore/relieve";
//搜索门店
static NSString * const searchStoreUrl = @"joinStore/search";
//条件查询
static NSString * const sortSearchStoreUrl = @"joinStore/sortSearch";

@implementation STHairService


#pragma mark -美发师
//查询认证状态
+(void)getStylistAuthStatus:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:1];
    [dicParameters setValue:[YLUserInfo sharedInstance].stylistId forKey:@"stylistId"];
    NSString * url =[requestIP stringByAppendingString:examineStatusUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}



#pragma mark -美发师服务管理
//美发师服务删除
+(void)deteleBarberServerWithServiceId:(int)serviceId online:(int)online completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:[NSNumber numberWithInt:serviceId] forKey:@"serviceId"];
//    [dicParameters setValue:[NSNumber numberWithInt:online] forKey:@"online"];
    NSString * url =[requestIP stringByAppendingString:deleteStylistServerUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}

//获取服务详情信息
+(void)getBarberServerInfoWithServiceId:(long)serviceId completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:[NSNumber numberWithInt:serviceId] forKey:@"serviceId"];
//    [dicParameters setValue:[NSNumber numberWithInt:online] forKey:@"online"];
    NSString * url =[requestIP stringByAppendingString:getServiceInfoUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}

//美发师服务上下架
+(void)changeBarberServerLineStatusWithServiceId:(int)serviceId online:(int)online completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:[NSNumber numberWithInt:serviceId] forKey:@"serviceId"];
    [dicParameters setValue:[NSNumber numberWithInt:online] forKey:@"online"];
    NSString * url =[requestIP stringByAppendingString:lineStatusUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}

//美发师服务列表查询接口
+(void)getBarberServerListWithOnline:(int)online page:(int)page completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:3];
    [dicParameters setValue:[YLUserInfo sharedInstance].stylistId forKey:@"stylistId"];
    [dicParameters setValue:[NSNumber numberWithInt:page] forKey:@"page"];
    [dicParameters setValue:[NSNumber numberWithInt:online] forKey:@"online"];
    NSString * url =[requestIP stringByAppendingString:serviceListUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
        
    }];
}

///美发师服务保存查询接口POST /stylistServer/save
+(void)saveBarberServerWithParameters:(NSDictionary *)paratemers completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithDictionary:paratemers];
    NSString * url =[requestIP stringByAppendingString:saveServiceUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}


///美发师服务类目
/**
 *packageType 套餐查询类型，0全部 1单项套餐里的可选类目 2套餐中的可选类目
 */
+(void)getBarberConditionWithPackageType:(int)packageType completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:1];
    [dicParameters setValue:@(packageType) forKey:@"packageType"];
    NSString * url =[requestIP stringByAppendingString:getConditionUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
        
    }];
}

//平台类目id 获取服务及选项
+(void)getCategoryById:(long)categoryId completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:@(categoryId) forKey:@"categoryId"];
    NSString * url =[requestIP stringByAppendingString:getCategoryUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}


#pragma mark -美发师时间管理
//查询美发师的时间设置列表
+(void)getStylistTimeSetting:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:1];
    [dicParameters setValue:[YLUserInfo sharedInstance].stylistId forKey:@"stylistId"];
    NSString * url =[requestIP stringByAppendingString:getStylistTimeUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
        
    }];
}
//单个的新增或者更新
+(void)updateStylistTimeSetOneParatemer:(NSDictionary *)parameter completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithDictionary:parameter];
    NSString * url =[requestIP stringByAppendingString:updateOneStylistTimeUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}
//多个的新增或者更新
+(void)updateStylistTimeSetArrParatemer:(NSArray *)parameters completion:(STResultObjectBlock)completion{
//    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithDictionary:parameter];
    NSString * url =[requestIP stringByAppendingString:updateAeeStylistTimeUrl];
    [STNetRequset netPostJsonRequestWithUrlStr:url withJsonDic:parameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
    }];
}

//订单统计
+(void)getStylistOrderCount:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:1];
    [dicParameters setValue:[YLUserInfo sharedInstance].stylistId forKey:@"stylistId"];
    NSString * url =[requestIP stringByAppendingString:stylistOrderCountUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}

+(void)getStylistSuccessOrdersWithFrom:(NSString *)fromTime end:(NSString *)endTime completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:3];
    [dicParameters setValue:[YLUserInfo sharedInstance].stylistId forKey:@"stylistId"];
    [dicParameters setValue:fromTime forKey:@"startTime"];
    [dicParameters setValue:endTime forKey:@"endTime"];
    NSString * url =[requestIP stringByAppendingString:stylistSuccessOrderCountUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}


#pragma mark -美发师和门店相关
//查询当前门店，技师申请状态
+(void)getHairJoinStoreStatusWithStoreId:(long)storeId completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:[NSNumber numberWithLong:storeId] forKey:@"storeId"];
    [dicParameters setValue:[YLUserInfo sharedInstance].userID forKey:@"userId"];
    NSString * url =[requestIP stringByAppendingString:getNexuStatusUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
        
    }];
}

//查询美发师入驻/签约门店
+(void)getHairSelfStore:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:3];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLongitude] forKey:@"lng"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLatitude] forKey:@"lat"];
    [dicParameters setValue:[YLUserInfo sharedInstance].userID forKey:@"userId"];
    NSString * url =[requestIP stringByAppendingString:getNexuStatusUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
        
    }];
}

//美发师申请入驻/签约门店
+(void)joinStoreWithStoreId:(long)storeId apply:(NSString *)apply completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:4];
    [dicParameters setValue:[NSNumber numberWithLong:storeId] forKey:@"storeId"];
    //TODO:获取美发师用户的stylistId
    [dicParameters setValue:[NSNumber numberWithInt:1] forKey:@"stylistId"];
    [dicParameters setValue:apply forKey:@"apply"];
    [dicParameters setValue:[YLUserInfo sharedInstance].userID forKey:@"userId"];
    NSString * url =[requestIP stringByAppendingString:joinStoreUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
    }];
}

//美发师解约门店
+(void)relieveStoreWithStoreId:(long)storeId completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:2];
    [dicParameters setValue:[NSNumber numberWithLong:storeId] forKey:@"storeId"];
    //TODO:获取美发师用户的stylistId
    [dicParameters setValue:[NSNumber numberWithInt:1] forKey:@"stylistId"];
    NSString * url =[requestIP stringByAppendingString:relieveStoreUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSDictionary * dicData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            dicData = [NSDictionary dictionaryWithDictionary:dicResult[@"data"]];
        }
        completion(dicData,error);
    }];
}

//搜索门店
+(void)searchStoreWithStoreStr:(NSString *)storeStr completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:3];
    [dicParameters setValue:storeStr forKey:@"search"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLongitude] forKey:@"lng"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLatitude] forKey:@"lat"];
    NSString * url =[requestIP1105 stringByAppendingString:searchStoreUrl];
    [STNetRequset netGetRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
    }];
}

//调整查询门店
/**
 *
 *categoryIds (Array[integer], optional): 理发类目Id ,
 *cityId (integer, optional): 城市ID，默认0 ,
 *districtId (integer, optional): 区ID，默认0 ,
 *lat (number, optional): 纬度 ,
 *lng (number, optional): 经度 ,
 *maxDistance (integer, optional): 距离范围（单位米），默认0不限制 ,
 *provinceId (integer, optional): 省ID，默认0 ,
 *sortType (integer, optional): 排序类型，0综合排序，1距离最近，2月结单量最多，3评论量最多 ,
 *
 */
+(void)relieveStoreWithCategoryIds:(NSArray *)categoryIds cityId:(int)cityId districtId:(int)districtId maxDistance:(long)maxDistance provinceId:(int)provinceId sortType:(int)sortType completion:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:9];
    [dicParameters setValue:categoryIds forKey:@"categoryIds"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLongitude] forKey:@"lng"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLatitude] forKey:@"lat"];
    
    [dicParameters setValue:[NSNumber numberWithInt:cityId] forKey:@"cityId"];
    [dicParameters setValue:[NSNumber numberWithInt:districtId] forKey:@"districtId"];
    [dicParameters setValue:[NSNumber numberWithLong:maxDistance] forKey:@"maxDistance"];
    [dicParameters setValue:[NSNumber numberWithInt:provinceId] forKey:@"provinceId"];
    [dicParameters setValue:[NSNumber numberWithInt:sortType] forKey:@"sortType"];
    [dicParameters setValue:[YLUserInfo sharedInstance].userID forKey:@"userId"];
    
    NSString * url =[requestIP1105 stringByAppendingString:sortSearchStoreUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
    }];
}

//我入驻/签约的门店
+(void)getHairStoreUrl:(STResultObjectBlock)completion{
    NSMutableDictionary * dicParameters = [NSMutableDictionary dictionaryWithCapacity:3];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLongitude] forKey:@"lng"];
    [dicParameters setValue:[NSNumber numberWithDouble:[YLUserInfo sharedInstance].selfLatitude] forKey:@"lat"];
    [dicParameters setValue:[YLUserInfo sharedInstance].userID forKey:@"userId"];
    NSString * url =[requestIP1105 stringByAppendingString:getHairStoreUrl];
    [STNetRequset netPostRequestWithUrlStr:url withParameters:dicParameters completion:^(id result, NSError *error) {
        NSDictionary * dicResult = [NSDictionary dictionaryWithDictionary:result];
        NSArray * arrData;
        if ([dicResult.allKeys containsObject:@"data"]) {
            arrData = [NSArray arrayWithArray:dicResult[@"data"]];
        }
        completion(arrData,error);
        
    }];
}















@end
